package com.sskj.gcc.ui.fragment;


import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.gcc.R;
import com.sskj.gcc.bean.SellInfo;
import com.sskj.gcc.presenter.BasePresenter;
import com.sskj.gocoin.common.App;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.utils.ToastUtil;
import com.sskj.lib.http.JsonCallBack;

/**
 * @author Hey
 * Create at  2019/07/29 15:08:08
 */
class OneSellPresenter extends BasePresenter<OneSellFragment> {


    public void getInfo(){
        OkGo.<HttpData<SellInfo>>post(HttpConfig.BASE_URL+HttpConfig.ONE_SELL)
                .execute(new JsonCallBack<HttpData<SellInfo>>(this){
                    @Override
                    public void onSuccess(Response<HttpData<SellInfo>> response) {
                        if (response.body().getCode() == 200) {
                            mView.setInfo(response.body().getData());
                        } else {
                            ToastUtil.showShort(response.body().getMsg());
                            mView.onGetpayInfoFail(response.body().getMsg());
                        }

                    }

                    @Override
                    public void onError(Response<HttpData<SellInfo>> response) {
                        super.onError(response);
                        mView.onGetpayInfoFail(App.INSTANCE.getString(R.string.one_sell_maintenance));
                    }
                });
    }

    public void sell(String num,String bank_name,String bank_open,String bank_num,String userName,String tpwd){
        OkGo.<HttpData<Object>>post(HttpConfig.BASE_URL+HttpConfig.DO_SELL)
                .params("num",num)
                .params("bank_name",bank_name)
                .params("bank_open",bank_open)
                .params("bank_num",bank_num)
                .params("username",userName)
                .params("tpwd", MD5Util.getMd5Value(tpwd))
                .execute(new JsonCallBack<HttpData<Object>>(this){
                    @Override
                    public void onSuccess(Response<HttpData<Object>> response) {
                        mView.sellSuccess();
                    }
                });

    }


}
